package learn.basics.anonymousinnerclass;

interface MyInterface {
    public abstract void Method1();

    public abstract void Method2();
}

class MyInterfaceImpl implements MyInterface {

    @Override
    public void Method1() {
        System.out.println("实现类覆盖重写了方法1");
    }

    @Override
    public void Method2() {
        System.out.println("实现类覆盖重写了方法2");
    }
}

class Demo1 {
    public static void Test() {

        //是匿名内部内，但不是匿名对象
        MyInterface obja = new MyInterface() {
            @Override
            public void Method1() {
                System.out.println("匿名内部实现1");
            }

            @Override
            public void Method2() {
                System.out.println("匿名内部实现2");

            }
        };


        obja.Method1();
        obja.Method1();
        System.out.println("===================");

        //是匿名内部类，也是匿名对象
        new MyInterface(){
            @Override
            public void Method1() {
                System.out.println("111");
            }

            @Override
            public void Method2() {
                System.out.println("2222");

            }
        }.Method1();
    }
}


public class TestAnonymousInnerClass {

    public static void main(String[] args) {
        Demo1.Test();
    }
}
